--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/marcmere/Box Sync/Shared_EffectofIncarceration_Pennslyvania/Replication Data/PA corrections/PACorrectionsData.log
  log type:  text
 opened on:  17 Dec 2016, 10:22:36

. 
. clear all 

. set more off

. 
. ***********************************************************************
. *
. * Table 2: Registration and Turnout among Pop. First Incarcerated Post-2008 and Eligible in 2012
. *
. ***********************************************************************
. 
. use "PAcorrectionsvfreplication.dta", clear

. 
. gen delta_reg=reg_12-reg_08

. gen delta_vote=vote_12final-vote_08final

. 
. label var reg_12 "Registered 2012 (1=yes)"

. label var reg_08 "Registered 2008 (1=yes)"

. 
. label var vote_12final "Voted 2012 (1=yes)"

. label var vote_08final "Voted 2008 (1=yes)"

. 
. label var delta_reg "Change in Registration 2012-2008"

. label var delta_vote "Change in Voting 2012-2008"

. 
. foreach var of varlist reg_12 vote_12final reg_08 vote_08final delta_reg delta_vote {
  2.  gen temp=`var'
  3.  local templabel : var label `var' 
  4.  if "`var'"=="reg_12" {
  5.   outsum temp using "Table02_PAIncarcerationPanel.out", replace bracket ctitle("`templabel'")
  6.  }
  7.  else {
  8.   outsum temp using "Table02_PAIncarcerationPanel.out", append bracket ctitle("`templabel'")
  9.  }
 10.  drop temp
 11. }

. 
. * Restricts to sample of people convicted in 2010 and discharged by 2011
. keep if (substr(first_movement, 1, 4) == "2010" | substr(first_movement, 1, 4) == "2011") & /*
> */ (substr(last_movement_pre2012, 1, 4) == "2010" | substr(last_movement_pre2012, 1, 4) == "2011")
(9802 observations deleted)

. 
. foreach var of varlist reg_12 vote_12final reg_08 vote_08final delta_reg delta_vote {
  2.  gen temp=`var'
  3.  local templabel : var label `var' 
  4.  if "`var'"=="reg_12" {
  5.   outsum temp using "Table02_PAIncarcerationPanelRestricted.out", /*
>   */ replace bracket ctitle("`templabel'")
  6.  }
  7.  else {
  8.   outsum temp using "Table02_PAIncarcerationPanelRestricted.out", /*
>   */ append bracket ctitle("`templabel'")
  9.  }
 10.  drop temp
 11. }

. 
. ***********************************************************************
. *
. * Table 3: Compares 2012 turnout of 2008 registrants who first went to prison to the general population 
. * Note that first column is presented last in final paper; it is done first here just for reasons of better labeling.
. *
. ***********************************************************************
. 
. use "PAvfcorrectionsreplication.dta", clear

. 
. * Drops if missing covariates
. drop if missing(dob)
(0 observations deleted)

. replace zipcode = substr(zipcode, 1, 5)
(66394 real changes made)

. destring zipcode, force replace
zipcode contains nonnumeric characters; replaced as long
(585 missing values generated)

. drop if missing(zipcode)
(585 observations deleted)

. 
. gen gender_male = (gender == "M")

. gen gender_unknown = (gender == "U") | missing(gender)

. gen pty_democrat = (party_id == "D")

. gen pty_republican = (party_id == "R")

. drop gender party_id first_movement last_movement_pre2012 

. 
. * Runs matched pair first (for labeling reasons)
. preserve

. keep if prison==0
(5414 observations deleted)

. save "temp_noprisonformerge.dta", replace
file temp_noprisonformerge.dta saved

. restore

. keep if prison==1
(8539069 observations deleted)

. rename dob dob_toprison

. rename id id_toprison 

. rename vote_12final vote_12final_toprison

. count
 5414

. joinby gender_male gender_unknown pty_democrat pty_republican zipcode vote_08final using "temp_noprisonformerge.dta", unmatched(master)

. !erase "temp_noprisonformerge.dta"

/bin/bash: erase: command not found

. tab _merge

                       _merge |      Freq.     Percent        Cum.
------------------------------+-----------------------------------
          only in master data |          2        0.00        0.00
both in master and using data |  8,941,846      100.00      100.00
------------------------------+-----------------------------------
                        Total |  8,941,848      100.00

. drop if _merge~=3
(2 observations deleted)

. drop _merge

. 
. gen age = ((mdy(11, 6, 2012) - dob) / 365.25) 

. gen age_toprison = ((mdy(11, 6, 2012) - dob_toprison) / 365.25) 

. 
. * Now score the age matches
. gen agediff=abs(age-age_toprison)

. * Require age to be withing 2.5 years on either side (5 year window)
. drop if agediff >2.5
(8008306 observations deleted)

. 
. gsort id_toprison agediff id

. drop if id_toprison==id_toprison[_n-1]
(928161 observations deleted)

. count
 5379

. 
. keep id id_toprison vote_12final vote_12final_toprison vote_08final age age_toprison

. 
. rename vote_12final X_GEN_2012_11_1

. rename vote_12final_toprison X_GEN_2012_11_2

. rename age age_1

. rename age_toprison age_2

. gen unique_person_id_sent_1 = id

. rename id_toprison unique_person_id_sent_2 

. gen upis = _n

. 
. reshape long X_GEN_2012_11_ age_ unique_person_id_sent_, i(upis vote_08final) j(treat) 
(note: j = 1 2)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                     5379   ->   10758
Number of variables                   9   ->       7
j variable (2 values)                     ->   treat
xij variables:
        X_GEN_2012_11_1 X_GEN_2012_11_2   ->   X_GEN_2012_11_
                            age_1 age_2   ->   age_
unique_person_id_sent_1 unique_person_id_sent_2->unique_person_id_sent_
-----------------------------------------------------------------------------

. replace treat=treat-1
(10758 real changes made)

. 
. rename X_GEN_2012_11_ X_GEN_2012_11

. rename treat prison

. rename age_ age

. rename unique_person_id_sent_ unique_person_id_sent

. 
. areg X_GEN_2012_11 prison age, absorb(upis) cluster(unique_person_id_sent)

Linear regression, absorbing indicators           Number of obs   =      10758
                                                  F(   2,  10738) =      18.68
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6095
                                                  Adj R-squared   =     0.2188
                                                  Root MSE        =     0.3941

              (Std. Err. adjusted for 10739 clusters in unique_person_id_sent)
------------------------------------------------------------------------------
             |               Robust
X_GEN_201~11 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      prison |   -.042765   .0076018    -5.63   0.000     -.057666    -.027864
         age |   .0844234   .0364172     2.32   0.020     .0130391    .1558078
       _cons |    -2.7444   1.311162    -2.09   0.036    -5.314519   -.1742809
-------------+----------------------------------------------------------------
        upis |   absorbed                                    (5379 categories)

. qui summ prison if e(sample)

. local numfelons=r(N)*r(mean)

. outreg2 using "Table03_PAVoterFilePanel.out", replace se bracket label /*
> */ dec(3) symbol(***, **, *)  /*
> */ addnote("Note: Cell entries are OLS estimates with robust standard errors in brackets. *p<.1; **p<.05; ***p<.01.") /*
> */ addstat("Number treated to prison", `numfelons')
dir : seeout

. 
. * Runs regressions using full dataset
. use "PAvfcorrectionsreplication.dta", clear

. 
. * Drops if Missing Covariates
. drop if missing(dob)
(0 observations deleted)

. replace zipcode = substr(zipcode, 1, 5)
(66394 real changes made)

. destring zipcode, force replace
zipcode contains nonnumeric characters; replaced as long
(585 missing values generated)

. drop if missing(zipcode)
(585 observations deleted)

. 
. label var vote_12final "Voted 2012 (1=yes)"

. 
. label var prison "Formerly Incarcerated (1=admitted to state prison after November 5, 2008 and released by September 30, 2016)"
note: label truncated to 80 characters

. 
. label var vote_08final "Voted 2008 (1=yes)"

. 
. 
. gen age = ((mdy(11, 6, 2012) - dob) / 365.25) 

. gen age2 = ((mdy(11, 6, 2012) - dob) / 365.25)^2 / 100

. label var age "Age in years (2012)"

. label var age2 "Age squared / 100"

. 
. gen pty_democrat = (party_id == "D")

. gen pty_republican = (party_id == "R")

. label var pty_democrat "Registered Democrat (1=yes)"

. label var pty_republican "Registered Republican (1=yes)"

. 
. gen gender_male = (gender == "M")

. gen gender_unknown = (gender == "U") | missing(gender)

. label var gender_male "Gender=Male"

. label var gender_unknown "Gender=Unknown"

. 
. count if prison==1
 5414

. local numfelons=r(N)

. 
. tab vote_12final prison, col

+-------------------+
| Key               |
|-------------------|
|     frequency     |
| column percentage |
+-------------------+

           | Formerly Incarcerated
           | (1=admitted to state
           | prison after November
Voted 2012 |    5, 2008 and rel
   (1=yes) |         0          1 |     Total
-----------+----------------------+----------
         0 | 3,842,928      4,053 | 3,846,981 
           |     45.00      74.86 |     45.02 
-----------+----------------------+----------
         1 | 4,696,141      1,361 | 4,697,502 
           |     55.00      25.14 |     54.98 
-----------+----------------------+----------
     Total | 8,539,069      5,414 | 8,544,483 
           |    100.00     100.00 |    100.00 


. tab vote_08final prison, col

+-------------------+
| Key               |
|-------------------|
|     frequency     |
| column percentage |
+-------------------+

           | Formerly Incarcerated
           | (1=admitted to state
           | prison after November
Voted 2008 |    5, 2008 and rel
   (1=yes) |         0          1 |     Total
-----------+----------------------+----------
         0 | 2,488,189      3,758 | 2,491,947 
           |     29.14      69.41 |     29.16 
-----------+----------------------+----------
         1 | 6,050,880      1,656 | 6,052,536 
           |     70.86      30.59 |     70.84 
-----------+----------------------+----------
     Total | 8,539,069      5,414 | 8,544,483 
           |    100.00     100.00 |    100.00 


. 
. regress vote_12final prison, robust

Linear regression                                      Number of obs = 8544483
                                                       F(  1,8544481) = 2562.49
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.0002
                                                       Root MSE      =  .49746

------------------------------------------------------------------------------
             |               Robust
vote_12final |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      prison |  -.2985741   .0058982   -50.62   0.000    -.3101344   -.2870138
       _cons |   .5499594   .0001702  3230.31   0.000     .5496257    .5502931
------------------------------------------------------------------------------

. outreg2 using "Table03_PAVoterFilePanel.out", bracket label /*
> */  dec(3) symbol(***, **, *) se addstat("Number treated to prison", `numfelons') append
dir : seeout

. 
. areg vote_12final prison, robust absorb(zipcode) 

Linear regression, absorbing indicators           Number of obs   =    8544483
                                                  F(   1,8542383) =    1980.95
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.0507
                                                  Adj R-squared   =     0.0504
                                                  Root MSE        =     0.4848

------------------------------------------------------------------------------
             |               Robust
vote_12final |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      prison |  -.2652243    .005959   -44.51   0.000    -.2769038   -.2535448
       _cons |   .5499382   .0001659  3314.53   0.000      .549613    .5502634
-------------+----------------------------------------------------------------
     zipcode |   absorbed                                    (2099 categories)

. local numzipfe = e(df_a)+ 1

. outreg2 using "Table03_PAVoterFilePanel.out", bracket label /*
> */ dec(3) symbol(***, **, *) se addstat("Number treated to prison", `numfelons', "Zip code fixed effects", `numzipfe') append
dir : seeout

. 
. areg vote_12final prison age age2 pty_democrat pty_republican gender_male gender_unknown, robust absorb(zipcode) 

Linear regression, absorbing indicators           Number of obs   =    8544483
                                                  F(   7,8542377) =   41927.80
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.0817
                                                  Adj R-squared   =     0.0815
                                                  Root MSE        =     0.4768

--------------------------------------------------------------------------------
               |               Robust
  vote_12final |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
        prison |  -.2294985    .005915   -38.80   0.000    -.2410916   -.2179054
           age |   .0021018   .0000272    77.25   0.000     .0020485    .0021551
          age2 |   8.69e-06    .000022     0.40   0.693    -.0000344    .0000518
  pty_democrat |    .119875   .0005376   222.99   0.000     .1188214    .1209287
pty_republican |   .1433199    .000556   257.78   0.000     .1422302    .1444096
   gender_male |  -.0173433   .0004222   -41.08   0.000    -.0181708   -.0165158
gender_unknown |  -.1366622   .0004278  -319.43   0.000    -.1375007   -.1358237
         _cons |   .3838364   .0009582   400.59   0.000     .3819584    .3857143
---------------+----------------------------------------------------------------
       zipcode |   absorbed                                    (2099 categories)

. local numzipfe = e(df_a)+ 1

. outreg2 using "Table03_PAVoterFilePanel.out", bracket label /*
> */ dec(3) symbol(***, **, *) se addstat("Number treated to prison", `numfelons', "Zip code fixed effects", `numzipfe') append
dir : seeout

. 
. areg vote_12final prison vote_08final age age2 pty_democrat pty_republican gender_male gender_unknown, robust absorb(zipcode) 

Linear regression, absorbing indicators           Number of obs   =    8544483
                                                  F(   8,8542376) =  512507.24
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.3240
                                                  Adj R-squared   =     0.3239
                                                  Root MSE        =     0.4091

--------------------------------------------------------------------------------
               |               Robust
  vote_12final |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
        prison |  -.0506416   .0057731    -8.77   0.000    -.0619566   -.0393266
  vote_08final |   .5521274   .0002992  1845.18   0.000      .551541    .5527139
           age |   .0010152   .0000194    52.22   0.000     .0009771    .0010533
          age2 |  -5.66e-07   .0000153    -0.04   0.970    -.0000305    .0000294
  pty_democrat |   .0459531   .0004701    97.76   0.000     .0450318    .0468745
pty_republican |     .07087   .0004808   147.39   0.000     .0699276    .0718124
   gender_male |  -.0022794   .0003661    -6.23   0.000     -.002997   -.0015618
gender_unknown |  -.0867674   .0003749  -231.46   0.000    -.0875021   -.0860327
         _cons |   .0906112    .000762   118.91   0.000     .0891177    .0921046
---------------+----------------------------------------------------------------
       zipcode |   absorbed                                    (2099 categories)

. local numzipfe = e(df_a)+ 1

. outreg2 using "Table03_PAVoterFilePanel.out", bracket label /*
> */ dec(3) symbol(***, **, *) se addstat("Number treated to prison", `numfelons', "Zip code fixed effects", `numzipfe') append
dir : seeout

. 
. log close
      name:  <unnamed>
       log:  /Users/marcmere/Box Sync/Shared_EffectofIncarceration_Pennslyvania/Replication Data/PA corrections/PACorrectionsData.log
  log type:  text
 closed on:  17 Dec 2016, 10:28:16
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
